libname ra "E:\data";/*cohort*/
libname pd "Z:\Medicare_20\Part_D";/*input part D*/
libname pb "Z:\Medicare_20\Part_b";/*input carrier*/
libname medpar "Z:\Medicare_20\MedPAR";/*input ip dataset*/
libname op "Z:\Medicare_20\OP";/*input op dataset*/
libname mbsf "Z:\Medicare_20\mbsf";/*input demo dataset*/


*****Purpose 1- get frequencies for table 2
             2- run propensity score adjusted logistic regression models**
             
       Note:  Dataset ra.cc1 contains analytical sample with cancer,heart failure 
              infection and concomitant meds use (as binary variable)in the year prior to stop date 
              Cancer, heart failure data were pulled from ip,op and part b files with claim dates 
              1 yr prior to stop date. Infection (serious infection requiring hospitalization)
              data were pulled from IP files
              Concomitant Medication use were pulled from part D files 

******************cancer, infection, heart-failure in the yr prior to de-escaltion**********;

********************freq and p-values****;

********freq for the entire sample****;

**disease**;
proc freq data= ra.cc1;
tables inf_12m new_cancer new_HF;
run;
**meds***;
proc freq data= ra.cc1;
tables gc_long90 CS_1yr_stop MTX_1yr_stop ;
run;

*****freq by desc status*********;

*****disease***;
proc freq data= ra.cc1;
tables inf_12m*desc01/chisq;
run;

proc freq data= ra.cc1;
tables new_cancer*desc01/chisq;
run;

proc freq data= ra.cc1;
tables new_hf*desc01/chisq;
run;

*****meds*********;
proc freq data= ra.cc1;
tables cs_1yr_stop*desc01/chisq;
run;

proc freq data= ra.cc1;
tables mtx_1yr_stop*desc01/chisq;
run;

proc freq data= ra.cc1;
tables gc_long90*desc01/chisq;
run;

************************************propensity score***********8************************;
****create baselineyear*****;
data cc1;
set ra.cc1;
year_index2= year (index2);

***************GET BASELINE AGE FROM 12m BEF STOP DATE****************************;
age_bl= (bl_dt - BENE_BIRTH_DT)/365.24;
run;


***********************************CANCER************************************;
********************include all covariates***********************;
proc logistic data=cc1;
class bene_sex_ident_cd race lis_pre_bin; 
model new_cancer (event="1") = age_bl bene_sex_ident_cd race lis_pre_bin comorb_bl year_index2/
 link=glogit rsquare;
/* Output propensity score */
 output out = ps_cancer1 pred = ps xbeta=logit_ps;
                                         
run;

proc means data= ps_cancer1;
class new_cancer;
var ps;
run;

****unadjusted***;
proc logistic data= ps_cancer1;
model desc01 (event= "1")= new_cancer ;
run;

*** propensity score adjusted***;

proc logistic data= ps_cancer1;
model desc01 (event= "1")= new_cancer ps;
run;



*********************************Heart Failure*********************************;
proc logistic data=cc1;
class bene_sex_ident_cd race lis_pre_bin; 
model new_hf = age_bl bene_sex_ident_cd race lis_pre_bin comorb_bl year_index2/
 link=glogit rsquare;
 /* Output propensity score */
 output out = ps_hf1 pred = ps xbeta=logit_ps;
run;

proc means data= ps_hf1;
class new_hf;
var ps;
run;

***unadjusted**;
proc logistic data= ps_hf1;
model desc01 (event= "1")= new_hf ;
run;

**PS adjusted***;
proc logistic data= ps_hf1;
model desc01 (event= "1")= new_hf ps;
run;



*********************************INFECTION*********************************;
proc logistic data=cc1;
class bene_sex_ident_cd race lis_pre_bin; 
model inf_12m = age_bl bene_sex_ident_cd race lis_pre_bin comorb_bl year_index2/
 link=glogit rsquare;
/* Output propensity score  */
 output out = ps_inf1 pred = ps xbeta=logit_ps;
run;

proc means data= ps_inf1;
class inf_12m;
var ps;
run;

***unadjusted***;
proc logistic data= ps_inf1;
model desc01 (event= "1")= inf_12m ;
run;

*****PS adjusted***;
proc logistic data= ps_inf1;
model desc01 (event= "1")= inf_12m ps;
run;

*********************CONCOMITANT MEDS*************************************;

***********************CS_DMARD*********************;

proc logistic data=cc1;
class bene_sex_ident_cd race lis_pre_bin; 
model cs_1yr_stop = age_bl bene_sex_ident_cd race lis_pre_bin comorb_bl year_index2/
 link=glogit rsquare;

/* Output propensity score  */
 output out = ps_cs1 pred = ps xbeta=logit_ps;

 
run;

proc means data= ps_cs1;
class cs_1yr_stop;
var ps;
run;

**unadjusted**;
proc logistic data= ps_cs1;
model desc01 (event= "1")= cs_1yr_stop ;
run;

** PS adjusted**;
proc logistic data= ps_cs1;
model desc01 (event= "1")= cs_1yr_stop ps;
run;

**************************Methotrexate*********************************;
proc logistic data=cc1;
class bene_sex_ident_cd race lis_pre_bin; 
model mtx_1yr_stop = age_bl bene_sex_ident_cd race lis_pre_bin comorb_bl year_index2/
 link=glogit rsquare;

/* Output propensity score  */
 output out = ps_mtx1 pred = ps xbeta=logit_ps;
run;

proc means data= ps_mtx1;
class mtx_1yr_stop;
var ps;
run;

***unadjusted**;
proc logistic data= ps_mtx1;
model desc01 (event= "1")= mtx_1yr_stop;
run;

*** ps adjusted**;
proc logistic data= ps_mtx1;
model desc01 (event= "1")= mtx_1yr_stop ps;
run;

**********************Glucocorticoids********************************;
proc logistic data=cc1;
class bene_sex_ident_cd race lis_pre_bin; 
model gc_long90 = age_bl bene_sex_ident_cd race lis_pre_bin comorb_bl year_index2/
 link=glogit rsquare;

/* Output propensity score */
 output out = ps_gc1 pred = ps xbeta=logit_ps;
run;


***unadjusted**;
proc logistic data= ps_gc1;
model desc01 (event= "1")= gc_long90 ;
run;

*** PS adjusted***;
proc logistic data= ps_gc1;
model desc01 (event= "1")= gc_long90 ps;
run;







